package com.market.model;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * 超市类
 */
public class Market {
    private final List<Fruit> fruits = new ArrayList<>(); // 水果列表

    // 添加水果
    public void addFruit(Fruit fruit) {
        fruits.add(fruit);
    }

    // 计算购物车总价
    public BigDecimal getTotalPrice() {
        BigDecimal totalPrice = BigDecimal.ZERO;
        for (Fruit fruit : fruits) {
            if (fruit.getDiscount() != null) {
                totalPrice = totalPrice.add(fruit.getDiscountPrice());
            } else totalPrice = totalPrice.add(fruit.getTotalPrice());
        }
        return totalPrice;
    }
}